/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.gitee.fdc.adminui.advice;

import java.text.SimpleDateFormat;
import java.util.Date;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.InitBinder;

/**
 *
 * @author MACHENIKE
 */
@ControllerAdvice
public class GlobalControllerAdvice {

    @InitBinder
    public void initBinder(WebDataBinder binder) {
        /*以下方法二选一，第一个无需添加MulitFormatDateEditor这个类*/

        //方法1：支持一个日期格式
        binder.registerCustomEditor(Date.class,
                new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true));

        //方法2：支持两个日期格式
        //true 允许属性为空verficationController
//        binder.registerCustomEditor(Date.class,
//                new MulitFormatDateEditor(new SimpleDateFormat("yyyy-MM-dd"),
//                        new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"), true));
    }

}
